﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace _09._04._2017.ArrayCollectionPractice
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] months = new string[] 
            {
                "Январь",
                "Февраль",
                "Март",
                "Апрель",
                "Май",
                "Июнь",
                "Июль",
                "Август",
                "Сентябрь",
                "Октябрь",
                "Ноябрь",
                "Декабрь"
            };

            string[] seasons = new string[14];
            months.CopyTo(seasons, 1);

            string[] seasons2 = new string[6];
            Array.Copy(months, seasons2, 6);

            //foreach (var item in seasons)
            //{
            //    Console.WriteLine(item);
            //}

            //Console.WriteLine();

            //foreach (var item in seasons2)
            //{
            //    Console.WriteLine(item);
            //}

            //Array.Sort(months);
            //Array.Reverse(months);

            //foreach (var item in months)
            //{
            //    Console.WriteLine(item);
            //}
            //Console.WriteLine();
            //Console.WriteLine(Array.IndexOf(months, "Ноябрь"));

            Comparator com = new Comparator();

            string[] monthsBeginsWithA = Array.FindAll(months, x => x[0] == 'А');

            string[] monthsBeg = Array.FindAll(months, x => x.Length < 4);

            //foreach (var item in monthsBeg)
            //{
            //    Console.WriteLine(item);
            //}

            Car[] cars = new Car[]
                {
                  new Car("Mercedes", 10000, "Blue", 1990, "S600"),
                  new Car("Audi", 20000, "Red", 1992, "A3"),
                  new Car("Renault", 5000, "Black", 1998, "Duster"),
                  new Car("BMW", 40000, "Black", 2000, "X5"),
                  new Car("BMW", 45000, "Red", 2003, "X6"),
                  new Car("Audi", 35000, "Silver", 1998, "A3"),
                  new Car("BMW", 33000, "White", 2003, "i3"),
                  new Car("Mazda", 22000, "White", 2004, "6"),
                  new Car("Mazda", 24000, "Blue", 2004, "3")
                };

            Car[] carsMorePrice = Array.FindAll(cars, car => car.Cost > 30000);

            Car[] carsSpecModel = Array.FindAll(cars, car => car.Brand == "Audi" || car.Brand == "BMW");

            Car[] carsSpecAudi = Array.FindAll(cars, car => car.Brand == "Audi" && car.Model == "A3");

            Car[] carsSpec = Array.FindAll(cars, car => (car.Brand != "Audi" && car.Color == "Red" && car.Cost > 15000
             && car.Cost < 55000));

            foreach (Car item in carsMorePrice)
            {
                Console.WriteLine(item.ToString());
            }

            Console.ReadKey();
        }
    }

    class Comparator: IComparer<string>
    {
        
        public int Compare(string x, string y)
        {
            if (x[x.Length - 1] > y[y.Length - 1])
                return -1;
            else if (x[x.Length - 1] == y[y.Length - 1])
                return 0;
            return 1;
        }
    }

    class Car
    {
        public string Brand { get; set; }
        public string Color { get; set; }
        public string Model { get; set; }
        public int Cost { get; set; }
        public int Year { get; set; }

        public Car(string brand, int cost, string color, int year, string model)
        {
            brand = Brand;
            cost = Cost;
            color = Color;
            year = Year;
            model = Model;
        }

        public override string ToString()
        {
            StringBuilder car = new StringBuilder();
            car.AppendFormat("{0} {1} {2} {3} {4}", Brand, Cost, Color, Year, Model);
            string c = car.ToString();
            return c;
        }
    }
}
